package com.molichuxing.services.business.convertor;

import com.molichuxing.services.business.dto.response.*;
import com.molichuxing.services.infrastructure.dto.response.*;
import com.molichuxing.services.infrastructure.dto.response.GoodsSpecDto;
import com.molichuxing.services.property.*;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @create_date: 2019/4/3
 * @name:member-service
 **/
public class Convert {

    /********************************************商品组合信息转换 开始 *****************************/
    public static List<GoodsBizBizDto> toGoodsBizBeanDto(List<GoodsBizBizDto> beanList, List<GoodsDealerDto> goodsDealerDtoList) {
        List<GoodsBizBizDto> dtoList = null;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsBizBizDto bean : beanList) {
                dtoList.add(toGoodsBizBeanDto(bean, goodsDealerDtoList));
            }
        }

        return dtoList;
    }

    public static GoodsBizBizDto toGoodsBizBeanDto(GoodsBizBizDto bean, List<GoodsDealerDto> goodsDealerDtoList) {
        if (bean != null) {
            if(null != goodsDealerDtoList && goodsDealerDtoList.size() > 0) {
                for(GoodsDealerDto goodsDealerDto : goodsDealerDtoList) {
                    if(bean.getGoodsId().equals(goodsDealerDto.getGoodsId())) {
                        bean.setUpperShelf(goodsDealerDto.getStatus());
                    }
                }
            }
        }
        return bean;
    }

    public static List<GoodsBizBizDto> toGoodsBaseProductDto(List<GoodsDto> beanList, Map<Integer, List<GoodsSpecDto>> specResultMap, List<GoodsSpecConfigDto> goodsProductSpecConfigList) {
        List<GoodsBizBizDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsDto bean : beanList) {
                dtoList.add(toGoodsBaseProductDto(bean, specResultMap, goodsProductSpecConfigList));
            }
        }
        return dtoList;
    }

    public static GoodsBizBizDto toGoodsBaseProductDto(GoodsDto bean, Map<Integer, List<GoodsSpecDto>> specResultMap, List<GoodsSpecConfigDto> goodsProductSpecConfigList) {
        GoodsBizBizDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsBizBizDto();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setGoodsId(bean.getId());
            if((null != specResultMap)&&(null != specResultMap.get(bean.getId()))) {
                List<GoodsSpecDto> goodsSpecDtoList =  specResultMap.get(bean.getId());
                if((null != goodsSpecDtoList)&&(goodsSpecDtoList.size() > 0)) {
                    encapsulationAttributes(beanDto, goodsSpecDtoList,goodsProductSpecConfigList);
                }
            }
        }
        return beanDto;
    }


    private static void encapsulationAttributes(GoodsSpecBizDto beanDto, List<GoodsSpecDto> goodsSpecDtoList, List<GoodsSpecConfigDto> goodsProductSpecConfigList) {
        for (GoodsSpecEnum goodsSpecSource : GoodsSpecEnum.values()) {
            List<Integer> specConfigList = getSpecListId(goodsSpecSource, goodsProductSpecConfigList);
            if (null != specConfigList) {
                for (GoodsSpecDto goodsSpecDto : goodsSpecDtoList) {
                    if (specConfigList.contains(goodsSpecDto.getSpecsId())) {
                        switch (goodsSpecSource) {
                            case DRIVING_TIME_LENGTH:
                                beanDto.setUseVehicleTime(Integer.parseInt(goodsSpecDto.getSpecsValue()));
                                break;
                            case IS_BUY_BACK:
                                beanDto.setIsBuyBack(Byte.parseByte(goodsSpecDto.getSpecsValue()));
                                break;
                            case PAYMENT_CYCLE:
                                beanDto.setPaymentCycle(Integer.parseInt(goodsSpecDto.getSpecsValue()));
                                break;
                        }
                    }
                }
            }
        }
    }


    public static List<GoodsBizBizDto> toGoodsSubscribeProductDto(List<GoodsBizBizDto> beanList, Map<Integer, GoodsSubscribeDto> goodsProductSubscribeMap,
                                                                  Map<Integer, List<GoodsSubscribeMileageDto>> goodsSubscribeMileageMap) {
        if (beanList != null && beanList.size() > 0) {
            for (GoodsBizBizDto bean : beanList) {
                List<GoodsSubscribeMileageDto> goodsSubscribeMileageDtoList = null;
                if((null != goodsSubscribeMileageMap)&&(null != goodsSubscribeMileageMap.get(bean.getGoodsId()))) {
                    goodsSubscribeMileageDtoList = goodsSubscribeMileageMap.get(bean.getGoodsId());
                }
                bean.setPackageList(toGoodsSubscribeProductDto(bean.getGoodsId(), goodsProductSubscribeMap.get(bean.getGoodsId()), goodsSubscribeMileageDtoList));
                bean.setServiceFee(goodsProductSubscribeMap.get(bean.getGoodsId()).getServiceFee());
                bean.setPaymentType(goodsProductSubscribeMap.get(bean.getGoodsId()).getPaymentType());
            }
        }
        return beanList;
    }

    public static List<GoodsPackageBizDto> toGoodsSubscribeProductDto(int goodsId, GoodsSubscribeDto goodsSubscribeDto,
                                                                      List<GoodsSubscribeMileageDto> goodsSubscribeMileageDtoList) {
        List<GoodsPackageBizDto> packageList = new ArrayList<>();
        GoodsPackageBizDto goodsPackageBizDto = new GoodsPackageBizDto();
        goodsPackageBizDto.setPackageType(GoodsMileageTypeEnum.BASE.getValue());
        goodsPackageBizDto.setMiles(goodsSubscribeDto.getBaseMileage());
        goodsPackageBizDto.setMilesPrice(goodsSubscribeDto.getBaseMileagePrice());
        packageList.add(goodsPackageBizDto);

        if(null != goodsSubscribeMileageDtoList && goodsSubscribeMileageDtoList.size() > 0) {
            for(GoodsSubscribeMileageDto goodsSubscribeMileageDto : goodsSubscribeMileageDtoList) {
                GoodsPackageBizDto goodsSubscribePackage = new GoodsPackageBizDto();
                goodsSubscribePackage.setId(goodsSubscribeMileageDto.getId());
                goodsSubscribePackage.setGoodsId(goodsSubscribeMileageDto.getGoodsId());
                goodsSubscribePackage.setPackageType(GoodsMileageTypeEnum.SUBSCRIBE.getValue());
                goodsSubscribePackage.setMiles(goodsSubscribeMileageDto.getMiles());
                goodsSubscribePackage.setMilesPrice(goodsSubscribeMileageDto.getMilesPrice());
                goodsSubscribePackage.setGiftMiles(goodsSubscribeMileageDto.getGiftMiles());
                packageList.add(goodsSubscribePackage);
            }
        }
        return packageList;
    }


    public static List<GoodsBizBizDto> toGoodsExclusiveProductDto(List<GoodsBizBizDto> beanList, Map<Integer, GoodsExclusiveDto> goodsProductExclusiveMap) {
        if (beanList != null && beanList.size() > 0) {
            for (GoodsBizBizDto bean : beanList) {
                toGoodsExclusiveProductDto(bean, goodsProductExclusiveMap);
            }
        }
        return beanList;
    }

    public static GoodsBizBizDto toGoodsExclusiveProductDto(GoodsBizBizDto bean, Map<Integer, GoodsExclusiveDto> goodsProductExclusiveMap) {
        if (bean != null) {
            if(null != goodsProductExclusiveMap && null != goodsProductExclusiveMap.get(bean.getGoodsId())) {
                GoodsExclusiveDto goodsExclusiveDto = goodsProductExclusiveMap.get(bean.getGoodsId());
                bean.setPaymentType(goodsExclusiveDto.getPaymentType());
                bean.setTransferTime(goodsExclusiveDto.getTransferTime());
                bean.setFirstTerms(goodsExclusiveDto.getFirstTerms());
                bean.setSettleDay(goodsExclusiveDto.getSettleDay());
                bean.setLimitMileage(goodsExclusiveDto.getLimitMileage());
                bean.setExclusiveType(goodsExclusiveDto.getExclusiveType());
            }
        }
        return bean;
    }


    private static List<Integer> getSpecListId(GoodsSpecEnum goodsSubscribeSpecSource, List<GoodsSpecConfigDto> goodsProductSpecConfigList) {
        if((null != goodsProductSpecConfigList)&&(goodsProductSpecConfigList.size() > 0)) {
            List<Integer> result = new ArrayList<>() ;
            for(GoodsSpecConfigDto goodsSpecConfigDto : goodsProductSpecConfigList) {
                if(goodsSpecConfigDto.getName().equals(goodsSubscribeSpecSource.getName())) {
                    result.add(goodsSpecConfigDto.getId());
                }
            }
            return result;
        }
        return null;
    }

    public static List<GoodsBizBizDto> toGoodsBizBizDto(List<GoodsBizBizDto> beanList, List<GoodsDealerDto> goodsDealerList) {
        if (beanList != null && beanList.size() > 0) {
            for (GoodsBizBizDto bean : beanList) {
                bean.setIsDistribution(false);
                if((null != goodsDealerList)&&(goodsDealerList.size() > 0)) {
                    for(GoodsDealerDto goodsDealer : goodsDealerList) {
                        if(bean.getGoodsId().equals(goodsDealer.getGoodsId())&&GoodsDealerStatusEnum.OPEN.getValue() == goodsDealer.getStatus()) {
                            bean.setIsDistribution(true);
                            continue;
                        }
                    }
                }
            }
        }
        return beanList;
    }

    public static List<GoodsBizBizDto> toGoodsAppDto(List<GoodsBizBizDto> beanList, List<GoodsDealerDto> goodsDealerList) {
        List<GoodsBizBizDto> result = new ArrayList<>();
        if((null != goodsDealerList)&&(goodsDealerList.size() > 0)) {
            for(GoodsDealerDto goodsDealer : goodsDealerList) {
                if (beanList != null && beanList.size() > 0) {
                    for (GoodsBizBizDto bean : beanList) {
                        if(bean.getGoodsId().equals(goodsDealer.getGoodsId())) {
                            //如果是订悦里程商品不展示
                            if(bean.getType() == GoodsTypeEnum.EXCLUSIVE.getValue()) {
                                if(bean.getExclusiveType() == GoodsExclusiveTypeEnum.ORDER_PLEASURE.getValue()) {
                                    continue;
                                }
                            }
                            composeAppGoods(bean);
                            result.add(bean);
                        }
                    }
                }
            }
        }
        return result;
    }

    public static List<GoodsBizBizDto> toGoodsAppByIdsDto(List<Integer> goodsIds, List<GoodsBizBizDto> beanList) {
        List<GoodsBizBizDto> result = new ArrayList<>();
            if (beanList != null && beanList.size() > 0) {
               Map<Integer ,GoodsBizBizDto> goodsMap = beanList.stream().collect(Collectors.toMap(GoodsBizBizDto::getGoodsId, a -> a,(k1,k2)->k1));
                for (Integer goodsId : goodsIds) {
                    GoodsBizBizDto goodsBizBizDto = goodsMap.get(goodsId);
                    if(null != goodsBizBizDto) {
                        composeAppGoods(goodsBizBizDto);
                        result.add(goodsBizBizDto);
                    }
                }
        }
        return result;
    }

    private static void composeAppGoods(GoodsBizBizDto goodsDto) {
        if(goodsDto.getType() == GoodsTypeEnum.EXCLUSIVE.getValue()) {
            goodsDto.setMonthlySupply(goodsDto.getRental().divide(new BigDecimal(goodsDto.getUseVehicleTime()), 2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString());
            goodsDto.setMileagePrice(goodsDto.getRental().divide(new BigDecimal(goodsDto.getUseVehicleTime()), 2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString());
        }else {
            List<GoodsPackageBizDto> goodsPackageList = goodsDto.getPackageList();
            BigDecimal minMileagePrice = new BigDecimal(Integer.MAX_VALUE);
            Integer packageId = null;
            if((null != goodsPackageList)&&(goodsPackageList.size() > 0)) {
                BigDecimal totalPrice = goodsPackageList.get(0).getMilesPrice();
                BigDecimal totalMileage = new BigDecimal(goodsPackageList.get(0).getMiles());
                for(GoodsPackageBizDto dto : goodsPackageList) {
                    if(dto.getPackageType() == GoodsMileageTypeEnum.SUBSCRIBE.getValue()) {
                        BigDecimal result = totalPrice.add(dto.getMilesPrice()).divide(totalMileage.add(new BigDecimal(dto.getMiles())), 2, RoundingMode.HALF_UP);
                        if(minMileagePrice.compareTo(result) > 0) {
                            minMileagePrice = result;
                            packageId = dto.getId();
                        }
                    }
                }
                goodsDto.setTotalMileage(totalMileage);
            }
            goodsDto.setPackageId(packageId);
            goodsDto.setMileagePrice(minMileagePrice.stripTrailingZeros().toPlainString());
            goodsDto.setMonthlySupply(minMileagePrice.stripTrailingZeros().toPlainString());
        }

    }
    /********************************************商品组合信息转换 结束 *****************************/

    /********************************************商品基本信息转换 开始 *****************************/
    public static GoodsBaseBizDto toGoodsBaseDto(GoodsDto goodsDto, List<GoodsSpecDto> goodsSpecDtoList,
                                                 List<GoodsSpecConfigDto> goodsProductSpecConfigList) {
        GoodsBaseBizDto goodsBaseBeanDto = new GoodsBaseBizDto();
        BeanUtils.copyProperties(goodsDto, goodsBaseBeanDto);
        goodsBaseBeanDto.setGoodsType(goodsDto.getType());
        goodsBaseBeanDto.setGoodsId(goodsDto.getId());
        if((null != goodsSpecDtoList)&&(goodsSpecDtoList.size() > 0)) {
            encapsulationAttributes(goodsBaseBeanDto, goodsSpecDtoList, goodsProductSpecConfigList);
        }
        return goodsBaseBeanDto;
    }

    /********************************************商品基本信息转换 结束 *****************************/

    /********************************************商品详细信息转换 开始 *****************************/
    public static GoodsDetailBizDto toGoodsExclusiveDetailDto(GoodsDto goodsDto, GoodsExclusiveDto goodsExclusiveDto,
                                                              List<GoodsSpecDto> goodsSpecDtoList, List<GoodsSpecConfigDto> goodsProductSpecConfigList) {
        GoodsDetailBizDto goodsDetailBeanDto = new GoodsDetailBizDto();
        BeanUtils.copyProperties(goodsDto, goodsDetailBeanDto);
        BeanUtils.copyProperties(goodsExclusiveDto, goodsDetailBeanDto);
        if((null != goodsSpecDtoList)&&(goodsSpecDtoList.size() > 0)) {
            encapsulationAttributes(goodsDetailBeanDto, goodsSpecDtoList, goodsProductSpecConfigList);
        }
        return goodsDetailBeanDto;
    }

    public static GoodsDetailBizDto toGoodsSubscribeDetailDto(GoodsDto goodsDto, GoodsSubscribeDto goodsSubscribeDto,
                                                              List<GoodsSubscribeMileageDto> goodsProductSubscribeMileageList) {
        GoodsDetailBizDto goodsDetailBeanDto = new GoodsDetailBizDto();
        goodsDetailBeanDto.setPackageList(toGoodsSubscribeProductDto(goodsDto.getId(), goodsSubscribeDto,goodsProductSubscribeMileageList ));
        return goodsDetailBeanDto;
    }

    public static GoodsOrderBizDto toGoodsOrderBizDto(GoodsBaseBizDto goodsBaseBeanDto, GoodsExclusiveDto goodsExclusiveDto) {
        GoodsOrderBizDto beanDto = null;
        if (goodsBaseBeanDto != null) {
            beanDto = new GoodsOrderBizDto();
            goodsBaseBeanDto.setTransferTime(goodsExclusiveDto.getTransferTime());
            goodsBaseBeanDto.setPaymentType(goodsExclusiveDto.getPaymentType());
            BeanUtils.copyProperties(goodsBaseBeanDto, beanDto);
            beanDto.setFirstTerms(goodsExclusiveDto.getFirstTerms());
            beanDto.setSettleDay(goodsExclusiveDto.getSettleDay());
            beanDto.setBuybackAmount(goodsExclusiveDto.getBuybackAmount());
            beanDto.setMinimunGuaranteeAmount(goodsExclusiveDto.getMinimunGuaranteeAmount());
            beanDto.setResiduaPurchaseAmount(goodsExclusiveDto.getResiduaPurchaseAmount());
            beanDto.setServiceFee(goodsExclusiveDto.getServiceFee());
            beanDto.setLimitMileage(goodsExclusiveDto.getLimitMileage());
            beanDto.setExclusiveType(goodsExclusiveDto.getExclusiveType());
            beanDto.setTransferFee(goodsExclusiveDto.getTransferFee());
        }
        return beanDto;
    }


    public static GoodsExclusiveDrawerBizDto toGoodsDrawerBizDto(GoodsBaseBizDto goodsBaseBeanDto, GoodsExclusiveDto goodsExclusiveDto) {
        GoodsExclusiveDrawerBizDto beanDto = null;
        if (goodsBaseBeanDto != null) {
            beanDto = new GoodsExclusiveDrawerBizDto();
            goodsBaseBeanDto.setPaymentType(goodsExclusiveDto.getPaymentType());
            BeanUtils.copyProperties(goodsBaseBeanDto, beanDto);
        }
        return beanDto;
    }

    public static GoodsSubscribeDrawerBizDto toGoodsSubscribeDrawerBizDto(GoodsBaseBizDto goodsBaseBeanDto, GoodsSubscribeDto goodsSubscribe, GoodsSubscribeMileageDto goodsSubscribeMileage) {
        GoodsSubscribeDrawerBizDto beanDto = null;
        if (goodsBaseBeanDto != null) {
            beanDto = new GoodsSubscribeDrawerBizDto();
            goodsBaseBeanDto.setPaymentType(goodsSubscribe.getPaymentType());
            BeanUtils.copyProperties(goodsBaseBeanDto, beanDto);

            beanDto.setPackageMileageId(goodsSubscribeMileage.getId());
            beanDto.setPackageMileage(goodsSubscribeMileage.getMiles());
            beanDto.setGiftMileage(goodsSubscribeMileage.getGiftMiles());
            beanDto.setBaseMileage(goodsSubscribe.getBaseMileage());
            beanDto.setTotalPrice(goodsBaseBeanDto.getRental().add(goodsSubscribe.getBaseMileagePrice()).add(goodsSubscribeMileage.getMilesPrice()));
        }
        return beanDto;
    }

    public static GoodsOrderBizDto toGoodsOrderBizDto(GoodsBaseBizDto goodsBaseBeanDto, GoodsSubscribeDto goodsSubscribeDto, GoodsSubscribeMileageDto goodsSubscribeMileage) {
        GoodsOrderBizDto beanDto = null;
        if (goodsBaseBeanDto != null) {
            beanDto = new GoodsOrderBizDto();
            BeanUtils.copyProperties(goodsBaseBeanDto, beanDto);
            beanDto.setPaymentType(goodsSubscribeDto.getPaymentType());
            beanDto.setBaseMileage(goodsSubscribeDto.getBaseMileage());
            beanDto.setBaseMileagePrice(goodsSubscribeDto.getBaseMileagePrice());
            beanDto.setServiceFee(goodsSubscribeDto.getServiceFee());
            if(null != goodsSubscribeMileage) {
                beanDto.setPackageMileageId(goodsSubscribeMileage.getId());
                beanDto.setPackageMileage(goodsSubscribeMileage.getMiles());
                beanDto.setPackageMileagePrice(goodsSubscribeMileage.getMilesPrice());
                beanDto.setGiftMileage(goodsSubscribeMileage.getGiftMiles());
                if(0 != goodsSubscribeMileage.getGiftMiles()) {
                    beanDto.setValuePrice(new BigDecimal(goodsSubscribeMileage.getGiftMiles()));
                }
            }
        }
        return beanDto;
    }


    public static List<GoodsBigScreenDrawerSpecBizDto> toGoodsBigScreenDrawerSpecBizDto(List<GoodsBizBizDto> goodsResult) {
        List<GoodsBigScreenDrawerSpecBizDto> specList = new ArrayList<>();
        if (goodsResult != null&&goodsResult.size() > 0) {
            for(GoodsBizBizDto goodsBizDto : goodsResult) {
                GoodsBigScreenDrawerSpecBizDto goodsDrawerSpecDto = new GoodsBigScreenDrawerSpecBizDto();
                goodsDrawerSpecDto.setGoodsId(goodsBizDto.getGoodsId());
                goodsDrawerSpecDto.setPaymentType(goodsBizDto.getPaymentType());
                goodsDrawerSpecDto.setUseVehicleTime(goodsBizDto.getUseVehicleTime());
                goodsDrawerSpecDto.setIsBuyBack(goodsBizDto.getIsBuyBack());
                if(goodsBizDto.getPaymentType() == GoodsPaymentTypeEnum.WHOLE_PARAGRAPH.getValue()) {
                    goodsDrawerSpecDto.setMonthlySupply(goodsBizDto.getRental());
                }else {
                    goodsDrawerSpecDto.setMonthlySupply(goodsBizDto.getRental().divide(new BigDecimal(goodsBizDto.getUseVehicleTime()), 2, RoundingMode.HALF_UP));
                }
                goodsDrawerSpecDto.setBond(goodsBizDto.getBond());
                goodsDrawerSpecDto.setRental(goodsBizDto.getRental());
                goodsDrawerSpecDto.setLimitMileage(goodsBizDto.getLimitMileage());
                goodsDrawerSpecDto.setTotalAmount(goodsDrawerSpecDto.getMonthlySupply().add(goodsBizDto.getBond()));
                specList.add(goodsDrawerSpecDto);
            }
        }
        return specList;
    }



    public static List<GoodsBigScreenDrawerMileageBizDto> toGoodsBigScreenDrawerMileageBizDto(List<GoodsBizBizDto> goodsResult) {
        List<GoodsBigScreenDrawerMileageBizDto> specList = new ArrayList<>();
        if (goodsResult != null&&goodsResult.size() > 0) {
            goodsResult = goodsResult.stream().sorted(Comparator.comparing(GoodsBizBizDto::getUseVehicleTime)).collect(Collectors.toList());
            for(GoodsBizBizDto goodsBizDto : goodsResult) {
                GoodsBigScreenDrawerMileageBizDto goodsDrawerSpecDto = new GoodsBigScreenDrawerMileageBizDto();
                goodsDrawerSpecDto.setUseVehicleTime(goodsBizDto.getUseVehicleTime());
                goodsDrawerSpecDto.setGoodsId(goodsBizDto.getGoodsId());
                goodsDrawerSpecDto.setBond(goodsBizDto.getBond());
                goodsDrawerSpecDto.setRental(goodsBizDto.getRental());
                if((null != goodsBizDto.getPackageList())&&(goodsBizDto.getPackageList().size() > 0)) {
                    List<GoodsBigScreenDrawerPackageDto> packageMileageList = new ArrayList<>();
                    for(GoodsPackageBizDto goodsPackage : goodsBizDto.getPackageList()) {
                        if(goodsPackage.getPackageType() == GoodsMileageTypeEnum.BASE.getValue()) {
                            goodsDrawerSpecDto.setBaseMileage(goodsPackage.getMiles());
                            goodsDrawerSpecDto.setBasePrice(goodsBizDto.getRental().add(goodsPackage.getMilesPrice()));
                        }else {
                            GoodsBigScreenDrawerPackageDto goodsDrawerPackageDto = new GoodsBigScreenDrawerPackageDto();
                            goodsDrawerPackageDto.setPackageMileageId(goodsPackage.getId());
                            goodsDrawerPackageDto.setPackageMileage(goodsPackage.getMiles());
                            goodsDrawerPackageDto.setPackageMileagePrice(goodsPackage.getMilesPrice());
                            goodsDrawerPackageDto.setPrice(goodsDrawerSpecDto.getBasePrice().add(goodsPackage.getMilesPrice()));
                            goodsDrawerPackageDto.setTotalAmount(goodsBizDto.getBond().add(goodsDrawerPackageDto.getPrice()));
                            goodsDrawerPackageDto.setGiftMileage(goodsPackage.getGiftMiles());
                            packageMileageList.add(goodsDrawerPackageDto);
                        }
                    }
                    goodsDrawerSpecDto.setPackageMileageList(packageMileageList);
                }
                specList.add(goodsDrawerSpecDto);
            }
        }
        return specList;
    }








    public static GoodsExclusiveDrawerBizDto toGoodsDrawerBizDto(GoodsExclusiveDrawerBizDto goodsExclusiveDrawerBizDto, List<GoodsBizBizDto> goodsResult) {
        List<GoodsDrawerSpecBizDto> specList = new ArrayList<>();
        if (goodsResult != null&&goodsResult.size() > 0) {
            for(GoodsBizBizDto goodsBizDto : goodsResult) {
                GoodsDrawerSpecBizDto goodsDrawerSpecDto = new GoodsDrawerSpecBizDto();
                goodsDrawerSpecDto.setGoodsId(goodsBizDto.getGoodsId());
                goodsDrawerSpecDto.setPaymentType(goodsBizDto.getPaymentType());
                goodsDrawerSpecDto.setUseVehicleTime(goodsBizDto.getUseVehicleTime());
                goodsDrawerSpecDto.setIsBuyBack(goodsBizDto.getIsBuyBack());
                if(goodsBizDto.getPaymentType() == GoodsPaymentTypeEnum.WHOLE_PARAGRAPH.getValue()) {
                    goodsDrawerSpecDto.setMonthlySupply(goodsBizDto.getRental().stripTrailingZeros().toPlainString());
                }else {
                    goodsDrawerSpecDto.setMonthlySupply(goodsBizDto.getRental().divide(new BigDecimal(goodsBizDto.getUseVehicleTime()), 2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString());
                }
                specList.add(goodsDrawerSpecDto);
            }
            goodsExclusiveDrawerBizDto.setSpecList(specList);
        }
        return goodsExclusiveDrawerBizDto;
    }


    public static GoodsSubscribeDrawerBizDto toGoodsDrawerBizDto(GoodsSubscribeDrawerBizDto goodsSubscribeDrawerBizDto, List<GoodsBizBizDto> goodsResult) {
        List<GoodsDrawerMileageBizDto> specList = new ArrayList<>();
        if (goodsResult != null&&goodsResult.size() > 0) {
            for(GoodsBizBizDto goodsBizDto : goodsResult) {
                GoodsDrawerMileageBizDto goodsDrawerSpecDto = new GoodsDrawerMileageBizDto();
                goodsDrawerSpecDto.setUseVehicleTime(goodsBizDto.getUseVehicleTime());
                goodsDrawerSpecDto.setGoodsId(goodsBizDto.getGoodsId());
                if((null != goodsBizDto.getPackageList())&&(goodsBizDto.getPackageList().size() > 0)) {
                    List<GoodsDrawerPackageDto> packageMileageList = new ArrayList<>();
                    for(GoodsPackageBizDto goodsPackage : goodsBizDto.getPackageList()) {
                        if(goodsPackage.getPackageType() == GoodsMileageTypeEnum.BASE.getValue()) {
                            goodsDrawerSpecDto.setBaseMileage(goodsPackage.getMiles());
                            goodsDrawerSpecDto.setBasePrice(goodsBizDto.getRental().add(goodsPackage.getMilesPrice()));
                        }else {
                            GoodsDrawerPackageDto goodsDrawerPackageDto = new GoodsDrawerPackageDto();
                            goodsDrawerPackageDto.setPackageMileageId(goodsPackage.getId());
                            goodsDrawerPackageDto.setPackageMileage(goodsPackage.getMiles());
                            goodsDrawerPackageDto.setPackageMileagePrice(goodsPackage.getMilesPrice());
                            goodsDrawerPackageDto.setTotalPrice(goodsBizDto.getRental().add(goodsDrawerSpecDto.getBasePrice()).add(goodsPackage.getMilesPrice()));
                            goodsDrawerPackageDto.setGiftMileage(goodsPackage.getGiftMiles());
                            packageMileageList.add(goodsDrawerPackageDto);
                        }
                    }
                    goodsDrawerSpecDto.setPackageMileageList(packageMileageList);
                }
                specList.add(goodsDrawerSpecDto);
            }
            goodsSubscribeDrawerBizDto.setMileageList(specList);
        }
        return goodsSubscribeDrawerBizDto;
    }



    public static List<GoodsReletMileageBizDto> toGoodsReletMileageBizDto(List<GoodsBizBizDto> beanList) {
        List<GoodsReletMileageBizDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsBizBizDto bean : beanList) {
                dtoList.add(toGoodsReletMileageBizDto(bean));
            }
        }
        return dtoList;
    }

    public static GoodsReletMileageBizDto toGoodsReletMileageBizDto(GoodsBizBizDto bean) {
        GoodsReletMileageBizDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsReletMileageBizDto();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setPackageList(toGoodsMileagePackageReletBizDto(bean.getPackageList()));
            beanDto.setSubscribeDuration(bean.getUseVehicleTime());
            beanDto.setSubscribeServiceFee(bean.getServiceFee());
            if((null != bean.getPackageList()) && (bean.getPackageList().size() > 0)) {
                GoodsPackageBizDto goodsPackageBizDto = bean.getPackageList().get(0);
                beanDto.setBaseMileagePrice(goodsPackageBizDto.getMilesPrice());
                beanDto.setBaseMileage(goodsPackageBizDto.getMiles());
            }
            if(null != beanDto.getPackageList()&&(beanDto.getPackageList().size() > 0)) {
                beanDto.getPackageList().remove(0);
            }
        }
        return beanDto;
    }


    public static List<GoodsMileagePackageReletBizDto> toGoodsMileagePackageReletBizDto(List<GoodsPackageBizDto> beanList) {
        List<GoodsMileagePackageReletBizDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsPackageBizDto bean : beanList) {
                dtoList.add(toGoodsMileagePackageReletBizDto(bean));
            }
        }
        return dtoList;
    }

    public static GoodsMileagePackageReletBizDto toGoodsMileagePackageReletBizDto(GoodsPackageBizDto bean) {
        GoodsMileagePackageReletBizDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsMileagePackageReletBizDto();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setPackageId(bean.getId());
            beanDto.setMiles(bean.getMiles());
            beanDto.setGiftMiles(bean.getGiftMiles());
            beanDto.setFee(bean.getMilesPrice());
        }
        return beanDto;
    }


    public static List<GoodsMileagePackageReletBizDto> toGoodsMileagePackageReletDto(List<GoodsBizBizDto> beanList) {
        List<GoodsMileagePackageReletBizDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsBizBizDto bean : beanList) {
                if((null != bean.getPackageList())&&(bean.getPackageList().size() > 0)) {
                    for(GoodsPackageBizDto goodsPackage : bean.getPackageList()) {
                        if(goodsPackage.getPackageType() == GoodsPackageTypeEnum.STAGES.getValue()) {
                            dtoList.add(toGoodsMileagePackageReletDto(goodsPackage));
                        }
                    }
                }
            }
        }
        return dtoList;
    }

    public static GoodsMileagePackageReletBizDto toGoodsMileagePackageReletDto(GoodsPackageBizDto bean) {
        GoodsMileagePackageReletBizDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsMileagePackageReletBizDto();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setPackageId(bean.getId());
            beanDto.setFee(bean.getMilesPrice());
            beanDto.setMiles(bean.getMiles());
        }
        return beanDto;
    }


    /********************************************商品详细信息转换 结束 *****************************/
}
